import os
import pymysql
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='demhghc', db='zthubo', charset='utf8')
# 创建游标
cursor = conn.cursor()
with open(os.path.dirname(__file__)+"/arp.txt","r") as file:
    l=file.readlines()
for i in l:
    
    ip = i[2:16].strip()
    mac=i[22:41].strip().upper()
    print("ip%d:%s mac%d:%s"%(len(ip),ip,len(mac),mac))
    effect_row = cursor.execute("update class_ip set mac = '%s' where ip = '%s'"%(mac,ip))
    conn.commit()
  
cursor.close()
conn.close()